//
//  MyHeaderView.m
//  有材网
//
//  Created by 肖扬 on 16/1/22.
//  Copyright © 2016年 肖扬. All rights reserved.
//

#import "MyHeaderView.h"

@implementation MyHeaderView
@synthesize mobileImg,emailImg,companyImg;
-(id)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        NSMutableDictionary *infoDic = [[NSUserDefaults standardUserDefaults] objectForKey:@"myInfo"];
        self.companyImg = [self createImageViewFrame:CGRectMake(0, (frame.size.width/3)-13, 13, 13) image:nil imageName:@"未实名认证" tag:0];
        [self addSubview:self.companyImg];
        if (![[infoDic objectForKey:@"license_status"]isEqualToString:@""]) {
            [self.companyImg setImage:[UIImage imageNamed:@"实名认证"]];
        }
        
        self.mobileImg = [self createImageViewFrame:CGRectMake(frame.size.width/3, (frame.size.width/3)-13, 13, 13) image:nil imageName:@"手机未认证" tag:0];
        [self addSubview:self.mobileImg];
        if ([[infoDic objectForKey:@"mobile_verified"]isEqualToString:@"1"]) {
            [self.mobileImg setImage:[UIImage imageNamed:@"手机认证"]];
        }
        
        self.emailImg = [self createImageViewFrame:CGRectMake((frame.size.width/3)*2, (frame.size.width/3)-13, 13, 13) image:nil imageName:@"邮箱未认证" tag:0];
        [self addSubview:self.emailImg];
        if (![[infoDic objectForKey:@"email"]isEqualToString:@""]) {
            [self.emailImg setImage:[UIImage imageNamed:@"邮箱认证"]];
        }
    }
    return self;
}
-(void)setPhoneState:(int)state{
    if (!state == 0) {
        self.companyImg.image = [UIImage imageNamed:@"实名认证"];
    }
}
-(void)setEmailState:(int)state{
    if (!state == 0) {
        self.mobileImg.image = [UIImage imageNamed:@"手机认证"];
    }
}
-(void)setCompanyState:(int)state{
    if (!state == 0) {
        self.emailImg.image = [UIImage imageNamed:@"邮箱认证"];
    }
}
//创建UIImageView tag值为五位数
- (UIImageView *)createImageViewFrame:(CGRect)frame
                                image:(UIImage *)image
                            imageName:(NSString *)imageName
                                  tag:(NSInteger)tag{
    UIImageView *tempImageView = [[UIImageView alloc]initWithFrame:frame];
    [tempImageView setBackgroundColor:[UIColor clearColor]];
    if (image) {
        tempImageView.image = image;
    }else{
        tempImageView.image = [UIImage imageNamed:imageName];
    }
    [tempImageView setTag:tag];
    return tempImageView;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
